<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/animate.css">
    <link rel="stylesheet" href="/css/style.css">
    <link rel="stylesheet" href="/font-awesome/css/font-awesome.css">
    <link rel="stylesheet" href="/css/plugins/iCheck/custom.css">
    <link rel="stylesheet" href="/css/plugins/toastr/toastr.min.css">
<style>
    .all {
        width: 800px;
        box-shadow: -10px 10px 25px rgba(210, 210, 210, 0.9);
        margin: auto;
        margin-top: 5%;
        display: flex;
        border-radius: 35px;
        background-color: #ffffff;
        height: 550px;
        background-image: url("img/backgroud.jpg");
        background-size: cover;
    }
    .log {
        width: 50%;
        margin: auto;
    }
    .reg {
        width: 50%;
        height: 100%;
        margin: auto;
        background-color: #20b2aa;
        border-radius: 35px;
        color: #ffffff;
    }
    .reg_1 {
        text-align: center;
        margin: auto;
        margin-top: 50%;
    }
    .reg_1 h2 {
        font-weight: 700;
    }
    .reg_1 p {
        margin: 15px 0px 25px 0px;
    }
    .sig {
        width: 70px;
        height: 30px;
        border-radius: 12px;
        background-color: #20b2aa;
        border-color: #fff;
        color: #ffffff;
    }
    /*#tiao {*/
    /*    padding: 0em 0;*/
    /*}*/
    .reg_1 a {
        color: #ffffff;
    }
    h3 {
        font-size: 3em;
        color: black;
        padding-bottom: 1em;
        margin: 0;
        text-align: center;
        font-family: "Marvel-Regular";
    }
    .input {
        margin: 10px 50px;
        width: 300px;
        height: 70px;
    }
    .input-trycode {
        margin: 10px 50px;
        width: 250px;
        height: 70px;
    }
    span {
        color: #999;
        font-size: 0.85em;
        padding-bottom: 0.2em;
        display: block;
        text-transform: uppercase;
        margin-bottom: 4px;
    }
    .ll {
        border: 1px solid #555;
        outline-color: #fd9f3e;
        width: 90%;
        font-size: 1em;
        padding: 0.5em;
        line-height: inherit;
    }
    .register-top-grid {
        color: black;
        padding-bottom: 1em;
        margin: 0;
        /* text-align: center; */
        font-family: "Marvel-Regular";
        margin: 10px 0;
    }
    .text-center {
        text-align: center;
    }
    .zhuce {
        border: none;
        font-size: 10px;
        color: rgb(255, 253, 253);
        width: 80px;
        height: 35px;
        background-color: rgb(241, 52, 10);
    }
    #roleStyle div{
        width: 95px;
        margin-top: 2px;
    }
    #roleStyle label{
        margin-bottom: 0px;
    }

    .toast-center-center {
        left: 50%;
        top: 40%;
        transform: translate(-50%,-50%);
    }
</style>
</head>
<body class="img-bg">
<div class="all">
    <div class="reg">
        <div class="reg_1">
            <h2>已有账号？</h2>
            <p>请使用你的账号进行登录！</p>
            <a href="/login">
                <button type="button" class="sig">登录</button>
            </a>
        </div>
    </div>
    <div class="log">
        <div>
            <div class="register">
                <form>
                    <div class="register-top-grid">
                        <h3 style="font-weight: normal">注册新用户</h3>
                        <div class="input">
                            <h3 style="font-family: 微软雅黑;font-size: 15px; text-align: left;font-weight: normal">用户名<label style="color: red">* </label></h3>
                            <input
                                    class="ll"
                                    type="text"
                                    placeholder="请输入用户名"
                                    v-model="name"
                                    id="account"
                                    maxlength="30"
                            />
                        </div>
                        <div class="input">
                            <h3 style="font-family: 微软雅黑;font-size: 15px; text-align: left;font-weight: normal">密码<label style="color: red">* </label></h3>
                            <input
                                    class="ll"
                                    type="password"
                                    placeholder="请输入密码"
                                    v-model="password"
                                    id="password"
                            />
                        </div>
                        <div class="input">
                            <h3 style="font-family: 微软雅黑;font-size: 15px; text-align: left;font-weight: normal">验证码<label style="color: red">* </label></h3>
                            <input
                                    type="text"
                                    placeholder="请输入验证码"
                                    v-model="trycode"
                                    id="tryCode"
                                    style="width: 155px;height: 35px;"
                            />
                            <img alt="验证码" onclick="this.src='/defaultKaptcha?d='+new Date()*1" src="/defaultKaptcha" id="img"/>
                        </div>

                        <div class="clearfix"></div>
                    </div>
                    <div class="text-center">
                        <input
                                type="button"
                                value="注册"
                                class="zhuce"
                                id="btn-register"
                        />
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="/js/jQuery.min.js"></script>
<script src="/js/plugins/toastr/toastr.min.js"></script>
<script type="text/javascript">
    $(function() {
        toastr.options = {
            "closeButton": true,// 是否显示关闭按钮
            "positionClass": "toast-center-center",// 弹出窗的位置
            "showDuration": "1000",// 显示的动画时间
            "hideDuration": "1000",// 消失的动画时间
            "timeOut": "1500",// 弹窗展现时间
            "showEasing": "swing",//显示时的动画缓冲方式
            "hideEasing": "linear",//消失时的动画缓冲方式
            "showMethod": "fadeIn",//显示时的动画方式
            "hideMethod": "fadeOut", //消失时的动画方式
            "allowHtml":true,// 允许弹窗内容包含 HTML 语言
        };

        $("#account").blur(function() {
            var account = $("#account").val();
            if (account.length > 30) {
                toastr.warning('用户名称过长！');
                $("#account").val('');
                return false;
            }
            if (account === '') {
                $('#error-log-username').show().text('用户名称不能为空').css("color","red");
                return false;
            }else {
                $('#error-log-username').hide();
            }
        })
        $("#password").blur(function() {
            var password = $("#password").val();
            var reg = /^[a-zA-z0-9]{6,12}$/;
            if (password === '') {
                $('#error-log-password').show().text('密码不能为空').css("color","red");
                return false;
            }
            if (reg.test(password) === false){
                $('#error-log-password').show().text('密码必须为6-12位数字').css("color","red");
                return false;
            }else {
                $('#error-log-password').hide();
            }
        })

        $("#btn-register").click(function() {
            if ($("#username").val()==="" || $("#password").val()==="" || $("#tryCode").val() ===""){
                toastr.warning('请填写相关信息');
                return;
            }else if ($("input[name='opo']:checked").val() === ""){
                toastr.warning('请选择身份');
                return;
            }else {
                $.ajax({
                    url : "/user/register",
                    type : "POST",
                    data : {
                        account: $("#account").val(),
                        password: $("#password").val(),
                        tryCode : $("#tryCode").val(),
                    },
                    dataType : "json",
                    success : function(data) {
                        if (data.state === 200) {
                            toastr.success('注册新用户成功,即将跳转至登录页面...');
                            // 设置1000毫秒后执行的定时任务
                            setTimeout(function() {
                                location.href = "/login";
                            }, 1500);
                        }else {
                            $("#account").val("");
                            $("#password").val("");
                            $("#tryCode").val("");
                            toastr.error(data.message);
                        }
                    }
                })
            }
        })
    })
</script>
</body>
</html>
